import redis
import time

# 连接到Redis服务器
redis_client = redis.StrictRedis(host='192.168.4.17', port=30056, db=7,password='Wanji@300552!')
# redis_client = redis.StrictRedis(host='106.120.201.126', port=14611, db=0, password='Wanji@300552!')
# 定义一个订阅者函数
def subscribe_channel(channel):
    pubsub = redis_client.pubsub()
    pubsub.subscribe(channel)

    # 开始监听消息
    for message in pubsub.listen():
        print(message)
        if message['type'] == 'message':

            print(f"Received av  message: {message['data'].decode('utf-8')}")

def subscribe_sv_channel(channel):
    pubsub = redis_client.pubsub()
    pubsub.subscribe(channel)

    # 开始监听消息
    for message in pubsub.listen():
        if message['type'] == 'message':

            print(f"Received sv  message: {message['data'].decode('utf-8')}")

if __name__ == "__main__":
    # 在一个线程中启动订阅者
    import threading
    subscriber_thread = threading.Thread(target=subscribe_channel, args=('admin_538_0_5_control',))
    # subscriber_thread.start()
    # subscriber_thread = threading.Thread(target=subscribe_sv_channel, args=('CDJHS_GKQResult_YK001_mixed',))
    # subscriber_thread.start()



